/**  
 
* @author xuzhixiang 

* @date 2018年12月13日  

*/
package leetcode;

/**
 * 
 * @author xuzhixiang
 * @date 2018年12月13日下午3:49:46
 */
public class Demo7 {
	public static int reverse(int x) {
		int count = 0;
		int temp = 0;
		int sum = 0;
		int[] a = new int[15];
		while (x != 0) {
			temp = x / 10;
			a[count] = x - (temp * 10);
			x = x / 10;
			count++;
		}
		sum = a[0];
		for (int i = 1; i < count; i++) {
			if (sum > Integer.MAX_VALUE / 10 || sum < -Integer.MAX_VALUE / 10) {
				sum = 0;
				break;
			}
			sum = sum * 10 + a[i];

		}
		return sum;

	}

	public static void main(String args[]) {
		System.out.println(reverse(123456));
	}
}
